/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.component.schedule.core.repository.mapper;

import info.peigen.hotpot.common.core.enums.YesOrNo;
import info.peigen.hotpot.component.data.repository.beetlsql.mapper.AbstractBeetlSqlMapper;
import info.peigen.hotpot.component.schedule.core.repository.entity.ScheduleJobEntity;
import org.beetl.sql.mapper.annotation.Select;
import org.beetl.sql.mapper.annotation.Sql;
import org.beetl.sql.mapper.annotation.Update;

import java.util.List;

/**
 * <b>(ScheduleJobMapper)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2022/12/30
 */
@SuppressWarnings("AlibabaAbstractMethodOrInterfaceMethodMustUseJavadoc")
public interface ScheduleJobMapper extends AbstractBeetlSqlMapper<ScheduleJobEntity> {
    @Sql("select * from schedule_job where job_name = ?")
    @Select
    ScheduleJobEntity findByJobName(String jobName);

    @Sql("select * from schedule_job where job_name = ? for update nowait")
    @Select
    ScheduleJobEntity lockByJobName(String jobName);

    @Sql("select * from schedule_job where yesOrNo = ?")
    @Select
    List<ScheduleJobEntity> findByEnable(YesOrNo yesOrNo);

    @Sql("update schedule_job set yesOrNo = ? where job_name = ?")
    @Update
    void changeJobEnableByName(YesOrNo yesOrNo, String jobName);

    @Sql("update schedule_job set yesOrNo = ?")
    @Update
    void changeAllJobsEnable(YesOrNo yesOrNo);

    @Sql("select * from schedule_job where yesOrNo = ? for update skip locked")
    @Select
    List<ScheduleJobEntity> lockByEnable(YesOrNo yesOrNo);

    @Sql("delete from schedule_job where job_name = ?")
    @Update
    void deleteByJobName(String jobName);
}